package impl;

import bean.Permission;
import dao.PermissionDao;
import util.DBHelper;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @classname:PermissionDaoImpl
 * @description:
 * @author: Mr.Z
 * @date: 2020/12/29 21:04
 * @version: 0.1
 * @since:1.8
 */
public class PermissionDaoImpl implements PermissionDao {
    private Connection conn;
    private String sql;
    private PreparedStatement ps;
    private ResultSet rs;


    //查询所有的父级权限信息
    @Override
    public List<Permission> selectAll() {
        conn = DBHelper.getCon();
        sql= "select * from tb_permission where parentPathId=0";
        List<Permission> list = new ArrayList<>(10);
        try {
            ps = conn.prepareStatement(sql);
            rs = ps.executeQuery();
            while (rs.next()){
                list.add(new Permission(rs));
            }
        } catch (SQLException e) {
            e.printStackTrace();
        }finally {
            DBHelper.closeResources(conn,ps,rs);
        }
        return list;
    }

}
